from datetime import datetime

from django.db import models
from user.models import User, Department


# # Create your models here.
# # 模板名
# class TemplateSheet(models.Model):
#     template_name = models.CharField(verbose_name="模板名称", max_length=64)
#
#
# # 审批类型
# class ApprovalType(models.Model):
#     approval_name = models.CharField(verbose_name="类型名称", max_length=64)
#     last_edit = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="最后编辑人", db_constraint=False)
#     template_id = models.ForeignKey(TemplateSheet, on_delete=models.CASCADE, verbose_name="模板id", db_constraint=False)
#     approval_title = models.CharField(verbose_name="审批表名", max_length=64)
#
#
# # 审批流程
# class ApprovalProcess(models.Model):
#     approvalProcess_type = models.ForeignKey(ApprovalType, on_delete=models.CASCADE, verbose_name="流程类型",
#                                              db_constraint=False)
#     status = models.IntegerField(verbose_name="0:禁用,1:启用", default=1)
#     approvalProcess_illustrate = models.CharField(verbose_name="流程说明", max_length=64)
#
#
# # 审批人流程表
# class ApprovalProcessUser(models.Model):
#     approvalProcess_id = models.ForeignKey(ApprovalProcess, on_delete=models.CASCADE, verbose_name="流程id",
#                                            db_constraint=False)
#     approval_user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="审批人", db_constraint=False)
#     num_user = models.IntegerField(verbose_name="第几级审批人")
#
#
# # 审批表
# class Approval(models.Model):
#     applicant = models.CharField(verbose_name="申请人", max_length=64)
#     applicant_user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="申请人id", db_constraint=False)
#     approval_type = models.ForeignKey(ApprovalType, on_delete=models.CASCADE, verbose_name="审批类型", db_constraint=False)
#     approval_time = models.DateTimeField(verbose_name="申请时间", default=datetime.now)
#     now_approval = models.IntegerField(verbose_name="当前展示审批人")
#     status = models.IntegerField(verbose_name="1:已通过,2:审批中,3:待审批,4:已撤销,0:已驳回")
#     reason = models.CharField(verbose_name="理由", max_length=64)
#
#
# # 审批表请假
# class LeaveApproval(models.Model):
#     approval_id = models.ForeignKey(Approval, on_delete=models.CASCADE, verbose_name="审批基本id",
#                                     db_constraint=False,  related_name="leave")
#     begin_time = models.DateTimeField(verbose_name="开始请假时间")
#     over_time = models.DateTimeField(verbose_name="结束请假时间")
#
#
# # 借款审批表
# class LoanApproval(models.Model):
#     approval_id = models.ForeignKey(Approval, on_delete=models.CASCADE, verbose_name="审批基本id",
#                                     db_constraint=False, related_name="loan")
#     begin_time = models.DateTimeField(verbose_name="借款日期")
#     loan_reason = models.CharField(verbose_name="借款原因", max_length=64)
#     loan_money = models.FloatField(verbose_name="借款金额")
#
#
# # 审批人
# class ApprovalUser(models.Model):
#     approval_user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="审批人", db_constraint=False)
#     approval_id = models.ForeignKey(Approval, on_delete=models.CASCADE, verbose_name="审批id", db_constraint=False)
#     flag = models.IntegerField(verbose_name="审批级别")
#     is_approval = models.IntegerField(verbose_name="是否审批过", default=0)


# 审批类型表
class ApprovalType(models.Model):
    types = models.CharField("类型",max_length=64)


# 审批人
class ApprovalUser(models.Model):
    approval_user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="审批人", db_constraint=False)
    flag = models.IntegerField(verbose_name="审批级别")
    is_approval = models.IntegerField(verbose_name="是否审批过", default=0)
    num_user = models.IntegerField(verbose_name="第几级审批人")


# 审批表
class Approval(models.Model):
    user = models.ForeignKey(User,on_delete=models.CASCADE,verbose_name="申请人")
    approval_type = models.ForeignKey(ApprovalType, on_delete=models.CASCADE, verbose_name="审批类型", db_constraint=False)
    approval_time = models.DateTimeField(verbose_name="申请时间", default=datetime.now)
    now_approval = models.ForeignKey(ApprovalUser,on_delete=models.CASCADE,verbose_name="当前审批人")
    status = models.IntegerField(choices=((1, "已通过"), (2, "已驳回"), (3, "待审批"), (4, "审批中"), (5, "已撤销")),default=3)
    reason = models.CharField(verbose_name="理由", max_length=64)
    department = models.ForeignKey(Department, on_delete=models.CASCADE, verbose_name="所属部门", db_constraint=False)


